#include<bits/stdc++.h>
using namespace std;

#define int long long 

const int N = 2e5 + 5;

int n;
int a[N],f[N][2],c[N];

void solve()
{
    cin >> n;
    for(int i = 1;i <= n;i++)
        cin >> a[i];
    for(int i = 2;i <= n;i++)
        if(a[i] == a[i - 1])
            c[i] = a[i];
    for(int i = 1;i <= n;i++)
        c[i] = c[i - 1] + c[i];
    // if(n<=15)
    // {
    //     for(int i = 1;i <= (1))
    //     return;
    // }
    for(int i = 1;i <= n;i++)
    {
        f[i][0] = f[i][1] = 0;
    }
    for(int i = 1;i <= n;i++)
    {   
        int max0 = 0;
        int max1 = 0;
        for(int j = i - 1;j >= 1;j--)
        // for(int j = 1;j <= i - 1;j++)
        {
            max0 = max(max0,f[j][0]);
            // max1 = max(max1,f[j][1]);
            if(a[i] != a[j])
            {
                f[i][0] = max(f[i][0],f[j][0]);
                // f[i][1] = max(f[i][1],f[j][0]);
            }
            else
            {
                // f[i][0] = max(f[i][0],max(a[i] + max1,f[j][1]));
                // f[i][1] = max(f[i][1],maxf[j][0],a[i] + max0));
                int x = 0;
                for(int k = j + 1;k <= i;k++)
                    if(a[k]==a[k-1])
                        x += a[k];
                f[i][0] = max(f[i][0],max0 + x + a[i]);
                // f[i][1] = max(f[i][1],max(f[j][0],a[i] + max0));
            }
        }
    }
    // for(int i = 1;i <= n;i++)
    // {
        // cout << f[i][0] << endl;
    // }
    cout << max(f[n][0],f[n][1]) << endl;
}
signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    // freopen("input.in","r",stdin);
    // freopen("output.out","w",stdout);
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int Test_case=1;
    cin >> Test_case;
    while(Test_case--)solve();
    return 0;
}